<?php
class v1_account{
    function password(){
    	$session=$this->yum->library('session');
		if($this->yum->post('save',true)){
			$data['message']=array('result'=>false,'msg'=>array());
			$password=$this->yum->post('password',true);
			$new=$this->yum->post('new',true);
			$affirm=$this->yum->post('affirm',true);
			if(strlen($password)==0){
				$data['message']['msg'][]='旧密码不可为空.';
			}else if(preg_match("/[^a-zA-Z_0-9]/",$new)>0){
				$data['message']['msg'][]='密码只可为a-z;A-Z;0-9;_的组合';
			}else if(strlen($new)<6||strlen($new)>32){
				$data['message']['msg'][]='密码长度为6-32个字符.';
			}else if(($affirm!=$new)){
				$data['message']['msg'][]='您输入的新密码和确认密码不同.';
			}else if($password==$new){
				$data['message']['msg'][]='旧密码与新密码不可相同.';
			}else{
				$member=$this->yum->model('member');
				$affected=$member->UMember(array('set'=>array('password ='=>$new),'where'=>array('id ='=>$session->GVAR('member'),'password ='=>$password)));
				if($affected==1){
					$data['message']['result']=true;
					$data['message']['msg'][]='密码修改成功.';
				}else{
					$data['message']['msg'][]='你输入的旧密码与帐户不匹配,请注意大小写.';
				}
			}
			$this->yum->set($data);
		}
		$this->yum->view('password.php');
    }
}
?>